package codesound;
import javax.sound.midi.*;

public class Helper {
	
	private static final int	VELOCITY = 120;
	
	public static Sequence sq = null;
	
	static{
		
		try {
			 sq = new Sequence(Sequence.PPQ, 1);
			
		} catch (InvalidMidiDataException e) {
			e.printStackTrace();
		}
		
	}
	
	public static MidiEvent createNoteOnEvent(int nKey, long lTick)
	{
		return createNoteEvent(ShortMessage.NOTE_ON, nKey, VELOCITY, lTick);
	}

	public static MidiEvent createNoteOffEvent(int nKey, long lTick){
		return createNoteEvent(ShortMessage.NOTE_OFF, nKey, 0, lTick);
		}
	
	public static MidiEvent createNoteEvent(int nCommand, int nKey, int nVelocity, long lTick){
		ShortMessage message = new ShortMessage();
		try{
			message.setMessage(nCommand,
			  0,	// always on channel 1
			  nKey,
			  nVelocity);
		}
		catch (InvalidMidiDataException e){
			e.printStackTrace();
		}
		MidiEvent	event = new MidiEvent(message, lTick);
		return event;
	}

}
